<?php $this->load->module('mobile/index/header', $common); ?>
<link rel="stylesheet" href="<?php echo URLPRE;?>static/template/<?php echo MOBILE_TEMPLATE_NAME?>/mobile/css/style1.css?_=22121" type="text/css">
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/main.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/dialog.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/base.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/index.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/line.css" />

<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/mobilecommon.js"></script>
<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/slider.js"></script>
<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/dialog.js"></script>
<style>
    .yudingitem select{
        width: auto!important;
        padding: 5px;
        float: right;
        margin-top: 7px;}
</style>
<div class="wrap" >
    <?php
    if(DEBUG){
        print_r($car);
    }
    ?>
    <div class="container">
        <div class="jipiaoyuding-city">
            <p><?php echo $car['brand']?></p>
            <span><?php echo $car['title']?></span>
        </div>
        <form action="" method="post">
            <div class="yudingitem">
                <p><?php echo $car['brand'].$cartypo[$car['car_type']];?>&nbsp;&nbsp;可载人数&nbsp;<?php echo $seat[$car['seat']]?></p>
            </div>
            <div class="yudingitem">
                <p><span>取车时间</span>

                <select id="start" name="go_date" onchange="return checktime();">
                    <?php foreach ($_time as $key => $item) {
                        echo "<option value='$item' data-value='$key'>$item</option>";
                    }?>
                </select>
                </p>
            </div>
            <div class="yudingitem">
                <p><span>还车时间</span>

                    <select id="end" onchange="return checktime();">
                        <?php foreach ($_time as $key => $item) {
                            echo "<option value='$item' data-value='$key'>$item</option>";
                        }?>
                    </select>
                </p>
            </div>
            <div class="yudingitem">
                <p><span>租车天数</span><span class="span-right"><font id="days">1</font>
                        <?php if($car['price_list'][0]['price_unit']=='1'):?>次<?php endif;?>
                        <?php if($car['price_list'][0]['price_unit']=='2'):?>天<?php endif;?>
                        </span></p>
            </div>
            <div class="yudingitem">
                <p><span>价格</span><span class="span-right">￥<font id="wsprice"><?php echo $car['price_list'][0]['ws_price']?></font>
                        <?php if($car['price_list'][0]['price_unit']=='1'):?>元/次<?php endif;?>
                        <?php if($car['price_list'][0]['price_unit']=='2'):?>元/天<?php endif;?>
                    </span></p>
            </div>
            <div class="yudingitem noborder">
                <p><span>辆数</span><span class="span-right">
                    <i class="item_minus" >-</i>
                    <input class="item_num" readonly="readonly" type="text" name="carnumber" id="carnumber" value="1" />
                    <i class="item_plus" id="sy_plus_gid1">+</i>
                </span></p>
            </div>
            <div class="linegrey"></div>
            <div class="yudingitem">
                <p><span>租车人</span><span class="span-right"><input name="contact_name" type="text" placeholder="填写租车人姓名"></span></p>
            </div>
            <div class="yudingitem">
                <p><span>手机号码</span><span class="span-right"><input name="contact_phone" type="text" placeholder="填写租车人手机号"></span></p>
            </div>
<!--            <div class="yudingitem">-->
<!--                <p><span>证件类型</span><span class="span-right left_black">身份证</span></p>-->
<!--            </div>-->
<!--            <div class="yudingitem noborder">-->
<!--                <p><span>身份证</span><span class="span-right "><input type="text" placeholder="填写租车人18位身份证号码"></span></p>-->
<!--            </div>-->
            <div class="linegrey"></div>
            <div class="item-price">
                <div class="wenxintishi">
                    <p>温馨提示：</p>
                    <p>1. 如需发票，可向租车公司咨询索要。</p>
                    <p>2. 在取车之前进行订单取消操作可取消订单；对于到时未取的订单，视为主动放弃，车辆不予保留；如提前还车，仍按照原预订租期计算费用，不做任何退还。</p>
                    <p>3. 请携带<span>您本人的二代有效身份证、本人有效地方驾驶证副本及信用卡</span>到门店办理组还车手续。</p>
                </div>
                <div class="pricebtn">
                    <p>订单总额：<b>￥<font id="total" ><?php echo $car['price_list'][0]['ws_price'] ?></font></b></p>
                    <a> <input type="hidden" name="id" value="<?php echo $car['id']?>"><input name="order_note" id="order_note" value="" type="hidden"><input type="button" onclick="return checkform();" value="提交订单"></a>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
$('.item_minus').on('click', function(){
    if(parseInt($('.item_num').val())>1){
        $('.item_num').val(parseInt($('.item_num').val())-1);
        sum11();
    }
});
$('.item_plus').on('click', function(){
    $('.item_num').val(parseInt($('.item_num').val())+1);
    sum11();
});
    function checktime(){
        var start = parseInt($('#start').find('option:selected').attr('data-value'));
        var end   = parseInt($('#end').find('option:selected').attr('data-value'));
        if(end<start){
            $('#start').val('<?php echo date('Y-m-d')?>');
            alert_popup('取车时间不能小于还车时间');
            return false;
        }
        $('#days').html(end-start+1);
        sum11();
    }
sum11();
function checkform(){
    if($('input[name="contact_name"]').val()==''){
        alert_popup('请填写租车人姓名');
        return false;
    }
    if($('input[name="contact_phone"]').val().length == 0){
        alert_popup('请输入手机号');
        return false;
    }else {
        var $val = $("input[name='contact_phone']").val();
        var length = $val.length;
        var status = (length == 11 && /^(((13[0-9]{1})|(15[0-9]{1})|(14[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test($val));
        if(status==false){
            alert_popup('请正确填写您的手机号码');
            return false;
        }
    }
    $.post('<?php echo get_url() ;?>',{
        id: $('input[name="id"]').val(),
        contact_name: $('input[name="contact_name"]').val(),
        contact_phone: $('input[name="contact_phone"]').val(),
        go_date: $('#start').val(),
        days: $('#days').html(),
        carnumber: parseInt($('#carnumber').val()),
        order_note: $('#order_note').val()
    },function(data){
        alert_popup(data.info);
        if(data.status=='1')
        {
            setTimeout(function(){
                window.location.href = data.url;
            }, 1200);
        }
    },'json');
    return false;
}

    function  sum11(){
        var days = parseInt($('#days').html());
        var wsprice = parseInt($('#wsprice').html());
        var carnumber = parseInt($('#carnumber').val());
        $('#total').html(days * wsprice * carnumber);
        $('#order_note').val(carnumber+'人，还车日期：'+$('#end').val() +'，单价：' + wsprice );
    }
function alert_popup(text){
    $.dialog({
        style:'tip',
        width:200,
        closeTime:1000,
        content: '<p style="text-align: center">'+text+'</p>'
    }).open();
}
</script>
<?php $this->load->module('mobile/index/footer', $common); ?>
